package com.zzptc.a11_24;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.zzptc.a11_24.entity.News;

import com.zzptc.a11_24.service.NewsService;


import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getNews();
    }

    private void getNews() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://v.juhe.cn/toutiao/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        NewsService newsService = retrofit.create(NewsService.class);
        Call<News> info = newsService.getInfo("top","6009331722a6ebf4594e50403fb3f821");
        info.enqueue(new Callback<News>() {
            @Override
            public void onResponse(Call<News> call, Response<News> response) {
                News userFactory=response.body();
                Log.d(TAG, "onResponse: "+userFactory.getResult().getData().get(0).getAuthor_name());

            }

            @Override
            public void onFailure(Call<News> call, Throwable t) {

            }
        });

    }
}
